import component from './toast.vue';
let index = 999999,
    arr = [], arrCopy = [];
function Toast (text, duration, type) {
    let div = document.createElement('div'),
        el = document.createElement('div'),
        props = {
            text: text,
            zIndex: index++,
            duration: duration,
            type: type
        };
    if (!/[0-9]/.test(props.duration)) {
        props.duration = 3000;
        props.type= duration;
    }
    document.body.appendChild(div);
    div.appendChild(el);
    let vueClass = Vue.extend(component);
    let vm = new vueClass({
        el: el,
        propsData: props
    });
    arr.push(1);
    vm.$on('close', function () {
        div.remove();
        arrCopy.push(arr.pop());
        if (arr.length == 0) {
            arrCopy.forEach(() => {
                --index;
            })
        }
    })
}

export default Toast;